package com.IC.base.controller;

import com.IC.base.service.ActualVehicleService;
import IC.common.core.domain.R;
import com.IC.base.util.ExcelUtils;
import com.IC.domain.po.ActualPopulationPo;
import com.github.pagehelper.PageInfo;
import com.IC.domain.dto.ActualVehicleDTO;
import com.IC.domain.po.ActualVehiclePO;
import com.IC.domain.vo.ActualVehicleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/vehicle")
public class ActualVehicleController {

    @Autowired
    private ActualVehicleService actualVehicleService;

    @PostMapping("/list")
    public R get(@RequestBody ActualVehicleDTO actualVehicleDTO) {
        PageInfo<ActualVehicleVO> findlist = actualVehicleService.findlist(actualVehicleDTO);
        return R.ok(findlist);
    }

    @GetMapping("/all")
    public R all() {
        List<ActualVehicleVO> all = actualVehicleService.all();
        return R.ok(all);
    }

    @RequestMapping("/add")
    public R add(@RequestBody ActualVehiclePO actualVehiclePO) {
        return R.ok(actualVehicleService.save(actualVehiclePO));
    }

    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id) {
        return R.ok(actualVehicleService.removeById(id));
    }

    @RequestMapping("/update")
    public R update(@RequestBody ActualVehiclePO actualVehiclePO) {
        return R.ok(actualVehicleService.updateById(actualVehiclePO));
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response){
        List<ActualVehicleVO> list=actualVehicleService.selectlist();
        ExcelUtils.export(response,"车辆信息",list,ActualVehicleVO.class);
    }

}
